home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 April / MacFormat CD Edition MF36 (April 1996).iso / Shareware City / Developers / Tools Plus - GUI⁄Event libs / Tools Plus 2.6.1a Evaluat'n Kit / Tools Plus 2.6.1a / Tutorials / 6-Picture Buttons / Tutorial.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-01  |  6.3 KB  |  185 lines  |  [TEXT/KAHL]

  1. //    Tools Plus Tutorial -- Picture Buttons
  2.  
  3.  
  4.  
  5.  
  6.  #include "ToolsPlus.h"
  7.  
  8.  
  9.  // Picture button constants to make code more readable…
  10.  #define LeftAlignButton        3
  11.  #define CenterAlignButton    4
  12.  #define RightAlignButton        5
  13.  #define JustifyButton            6
  14.  #define CutButton                    7
  15.  #define BucketButton                8
  16.  #define ClipboardButton        9
  17.  #define PrinterButton            12
  18.  #define ModemButton                13
  19.  #define ScrollingButton        15
  20.  #define PowerButton                23
  21.  #define DoneButton                    25
  22.  
  23.  // Picture button icon constants to make code more readable…
  24.  #define PrinterIcon                150
  25.  #define ModemIcon                    151
  26.  #define LeftAlignIcon            408
  27.  #define CenterAlignIcon        409
  28.  #define RightAlignIcon            410
  29.  #define JustifyIcon                411
  30.  #define CutIcon                        412
  31.  #define BucketIcon                    413
  32.  #define ClipboardIcon            414
  33.  #define PowerIcon                    450
  34.  #define ScrollingIcon            458
  35.  #define DoneIcon                        464
  36.  
  37.  
  38.  
  39.  
  40.  TPPollRecord        Poll;                    // Polling record to retrieve event information
  41.  Boolean                ExitTheDemo;    // Should the demo terminate?
  42.  
  43.  short                    theButton;        // Button counter
  44.  
  45.  
  46.  void ApplicationInitialization (void);
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  //    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -
  54.  void main(void)
  55.  {
  56.     InitGraf(&qd.thePort);
  57.     InitFonts();
  58.     InitWindows();
  59.     InitMenus();
  60.     TEInit();
  61.     InitDialogs(0L);
  62.     MaxApplZone();
  63.  
  64.  
  65.     if (!InitToolsPlus(1, 2, UseColor))
  66.         ExitToShell();
  67.  
  68.     ApplicationInitialization();
  69.  
  70.     while (!ExitTheDemo)                    //Main Event Loop
  71.         {
  72.         if (PollSystem(&Poll))            //If an event is available, process the event…
  73.             {
  74.             switch (Poll.What)
  75.                 {
  76.                 case doPictButton:
  77.                     switch (Poll.Button.Num)
  78.                         {
  79.                         case LeftAlignButton:  case CenterAlignButton:
  80.                         case RightAlignButton: case JustifyButton:
  81.                             // Cycle through the group and turn off the buttons
  82.                             //    that weren't clicked (deselect them)…
  83.                             for (theButton = LeftAlignButton; theButton <= JustifyButton; theButton++)
  84.                                 SelectPictButton(theButton, theButton == Poll.Button.Num);
  85.                             break;
  86.  
  87.                         case PrinterButton: case ModemButton:
  88.                             // Cycle through the group and turn off the buttons
  89.                             //    that weren't clicked (deselect them)…
  90.                             for (theButton = PrinterButton; theButton <= ModemButton; theButton++)
  91.                                 SelectPictButton(theButton, theButton == Poll.Button.Num);
  92.                             break;
  93.  
  94.                         case DoneButton: 
  95.                             ExitTheDemo = true;
  96.                             break;
  97.  
  98.                         default:    // Ignore all other buttons…
  99.                             break;
  100.                         }
  101.                     break;
  102.  
  103.                 case doMenu:    // The only menu item available is "Quit"…
  104.                     ExitTheDemo = true;
  105.                     break;
  106.  
  107.                 case doChgWindow:    // Activate the clicked window…
  108.                     ActivateWindow(Poll.Window);
  109.                     break;
  110.  
  111.                 default:
  112.                     break;            //All other events are ignored
  113.                 }
  114.             }
  115.         }
  116.  }
  117.  
  118.  
  119.  
  120.  //    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -
  121.  void ApplicationInitialization (void)
  122.     {
  123.     //    Do all the application setup before you start polling for events…
  124.  
  125.      #define        DemoWindow1        1
  126.      #define        DemoWindow2        2
  127.  
  128.     // This big 3D button stays down when selected, lightens when selected,
  129.     // and gets whited out when disabled…
  130.      #define        Big3Dspec                    picbutLockSelected + picbutBigSICN3D + picbutSelectLightenSICN3D + picbutDimUsingWhite
  131.  
  132.     // This small 3D button pops back up after being selected, lightens wheN
  133.     // selected, and gets whited out when disabled…
  134.      #define        Small3Dspec                picbutSelectLightenSICN3D + picbutDimUsingWhite
  135.  
  136.     // This ordinary icon (printer and modem) is selected when the mouse-down occurs,
  137.     // stays down when selected, darkens when selected.  When disabled, a white
  138.     // screen effect is used and the border is preserved…
  139.      #define        OrdinaryIconSpec    picbutInstantEvent + picbutLockSelected + picbutSelectDarken + picbutDimUsingWhite + picbutDimLeaveBorder
  140.  
  141.  
  142.  
  143.     // Do all the application setup before you start polling for events…
  144.     AppleMenu("\p");
  145.     Menu(1, 0, enabled, "\pFile");
  146.     Menu(1, 1, enabled, "\pQuit/Q");
  147.     UpdateMenuBar();
  148.  
  149.  
  150.     WindowOpen(DemoWindow1, 0, 0, 215, 160, "\pDummy Window", noGrowDocProc + wCenter, NoGoAway, NotModal);
  151.     WindowOpen(DemoWindow2, 0, 0, 215, 160, "\pPicture Buttons", noGrowDocProc + wTile, NoGoAway, NotModal);
  152.  
  153.     NewPictButton(LeftAlignButton, 12, 8, LeftAlignIcon, Big3Dspec, enabled, notSelected, 0, 0, 0);
  154.     NewPictButton(CenterAlignButton, 35, 8, CenterAlignIcon, Big3Dspec, enabled, notSelected, 0, 0, 0);
  155.     NewPictButton(RightAlignButton, 58, 8, RightAlignIcon, Big3Dspec, enabled, notSelected, 0, 0, 0);
  156.     NewPictButton(JustifyButton, 81, 8, JustifyIcon, Big3Dspec, enabled, notSelected, 0, 0, 0);
  157.  
  158.     NewPictButton(CutButton, 128, 9, CutIcon, Small3Dspec, enabled, notSelected, 0, 0, 0);
  159.     NewPictButton(BucketButton, 151, 9, BucketIcon, Small3Dspec, enabled, notSelected, 0, 0, 0);
  160.     NewPictButton(ClipboardButton, 174, 9, ClipboardIcon, Small3Dspec, enabled, notSelected, 0, 0, 0);
  161.  
  162.     NewPictButton(PrinterButton, 22, 50, PrinterIcon, OrdinaryIconSpec, enabled, selected, 0, 0, 0);
  163.     NewPictButton(ModemButton, 63, 50, ModemIcon, OrdinaryIconSpec, enabled, notSelected, 0, 0, 0);
  164.  
  165.     // This is a dual state button (Power-On, Power-Off), so it is considered to be a
  166.     //    "Multi-Stage" button (Off=0, 1=On). The button's value changes automatically
  167.     //    when selected by the user.  The values "wrap" to allow 1 (on) to start back
  168.     //    at 0 (off) again.  An alternate icon is used to depict the selected button
  169.     //    (down position), and disabled button for maximum visual control…
  170.     NewPictButton(PowerButton, 131, 50, PowerIcon, picbutMultiStage + picbutAutoValueChg + picbutValueWrap + picbutSelectAltImage + picbutDimAltImage, enabled, notSelected, 0, 0, 1);
  171.  
  172.     // This scrolling button has nine icon images in its SICN resource.  It keeps
  173.     //    producing doPictButton events while the mouse is held down.  The button's
  174.     //    value changes automatically with the top 1/2 of the button incrementing the
  175.     //    value and the bottom 1/2 decrementing it.  This is a BIG 3D button that looks
  176.     //    "pushed" when selected (not darker or ligher)…
  177.     NewPictButton(ScrollingButton, 172, 55, ScrollingIcon, picbutRepeatEvents + picbutAutoValueChg + picbutTopBottomSplit + picbutBigSICN3D + picbutSelectPushedSICN3D, enabled, notSelected, 1, 5, 9);
  178.  
  179.     // This is a really simple push-button that uses an alternate icon when the
  180.     //    button is selected. When disabled, a white screen is overlayed and the
  181.     //    border is preserved…
  182.     NewPictButton(DoneButton, 131, 130, DoneIcon, picbutSelectAltImage + picbutDimUsingWhite + picbutDimLeaveBorder, enabled, notSelected, 0, 0, 0);
  183.  
  184.     ExitTheDemo = false;
  185.     }